package org.ezjava.rpc.sb.provider.rpc;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TSimpleServer;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TTransportException;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

/**
 * @author Erik
 * @create 2021-08-04 17:15
 * @description
 **/

@Component
@Slf4j
public class TFServer {

    public TFServer() {
        log.info("init TFServer!!!");
    }

    @Autowired
    private HelloWorldServiceImpl helloWorldService;

    @Getter
    private TServer server;

    public void startServer(){
        try {
            log.info("hhh");
            log.info("HelloWorldServer start ... ");
            TServerSocket serverTransport = new TServerSocket(8888);
            TServer.Args tArgs = new TServer.Args(serverTransport);
            TProcessor tProcessor = new HelloWorldService.Processor<HelloWorldService.Iface>(helloWorldService);
            tArgs.processor(tProcessor);
            tArgs.protocolFactory(new TBinaryProtocol.Factory());
//            tArgs.protocolFactory(new TCompactProtocol.Factory());
//            tArgs.protocolFactory(new TJSONProtocol.Factory());
            server = new TSimpleServer(tArgs);
            server.serve();
        } catch (TTransportException e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args){
        TFServer serviceServer = new TFServer();
        serviceServer.startServer();
    }
}
